$(function () {

    $(".btn-primary").click(function (event) {
        event.preventDefault();
        let username = $(".user").val()
        let password = $(".passw").val()
        $.post(
            "api/userLogin",
            {
                userName: username,
                userPassword: password,
            },
            function (res) {
                console.log(res)

                if (res && res.data && res.data.userName === username) {
                    localStorage.setItem("lqtoken", "username:"+username+";id:"+res.data._id+";id:"+res.data.headImg)
                    window.location.href = "./index.html"
                } else {
                    
                    $(".alert").css("display", "block")
                    //防止重复添加
                    if ($(".alert").length <= 0) {
                        $("section").append(`        <div class="alert alert-warning alert-dismissible fade show" role="alert">
                            <strong>提示：</strong> 账号或密码错误！
                            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                        </div>`)
                    }
                }
            }
        )
    })
})
